#!/bin/sh

#
# This file is released under the terms of the Artistic License.
# Please see the file LICENSE, included in this package, for details.
#
# Copyright (C) 2002-2010 Mark Wong & Open Source Development Labs, Inc.
#               2006 Rilson Nascimento
#

# FIXME: Currently assumes we are loading in the C stored functions.  More
# logic needed to also handle plpgsql if so desired.

while getopts "d:p:q" OPT; do
	case ${OPT} in
	d)
		DBT5DBNAME=${OPTARG}
		;;
	p)
		PORT=${OPTARG}
		;;
	q)
		LANGDIR="pgsql"
		;;
	esac
done

if [ ! "x${DBT5DBNAME}" = "x" ]; then
	DBNAMEARG="-d ${DBT5DBNAME}"
fi

if [ ! "x${PORT}" = "x" ]; then
	PORTARG="-p ${PORT}"
fi

PSQL="psql ${PORTARG} ${DBNAMEARG}"
# SHAREDIR=`pg_config --sharedir`
PGPL_DIR="${EGENDIR}/../storedproc/pgsql/pgsql"

# Broker Volume transaction
${PSQL} -f ${PGPL_DIR}/broker_volume.sql || exit 1

# Customer Position transaction
${PSQL} -f ${PGPL_DIR}/customer_position.sql || exit 1

# Data Maintenance transaction
${PSQL} -f ${PGPL_DIR}/data_maintenance.sql || exit 1

# Market Feed transaction
${PSQL} -f ${PGPL_DIR}/market_feed.sql || exit 1

# Market Watch transaction
${PSQL} -f ${PGPL_DIR}/market_watch.sql || exit 1

# Security Detail transaction
${PSQL} -f ${PGPL_DIR}/security_detail.sql || exit 1

# Trade Cleanup transaction
${PSQL} -f ${PGPL_DIR}/trade_cleanup.sql || exit 1

# Trade Lookup transaction
${PSQL} -f ${PGPL_DIR}/trade_lookup.sql || exit 1

# Trade Order transaction
${PSQL} -f ${PGPL_DIR}/trade_order.sql || exit 1

# Trade Result transaction
${PSQL} -f ${PGPL_DIR}/trade_result.sql || exit 1

# Trade Status transaction
${PSQL} -f ${PGPL_DIR}/trade_status.sql || exit 1

# Trade Update transaction
${PSQL} -f ${PGPL_DIR}/trade_update.sql || exit 1
